perm filename MAN2.TEX[TEX,ALS] blob sn#603452 filedate 1981-08-04 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\input manhdr[tex,dek]  % This is the TEX user manual source text
C00004 00003	\chapterbegin 21. {Making boxes}
C00022 00004	\specialchapterbegin 22. {Alignment}
C00049 ENDMK
C⊗;
\input manhdr[tex,dek]  % This is the TEX user manual source text
\titlepage
\tenpoint
\null\vskip-46pt
\hbox to size{\:<Stanford Artificial Intelligence Laboratory\hfill September
1979}
\hbox to size{\:<Memo AIM-317.3\hfill(fourth printing)}
\vskip .25in
\hbox{\:<Computer Science Department}
\hbox{\:<Report No. STAN-CS-78-675}
\vfill
\ctrline{\:<TAU EPSILON CHI, a system for technical text}
\vskip .25in
\ctrline{$\copyright$ 1979 by the American Mathematical Society}
\vfill
{\baselineskip 7pt
\:f The author wishes to thank the many individuals who made
helpful comments on the first drafts of this manual, and especially Leo
Guibas for his help in producing copies on experimental graphics printing
equipment. Thanks are also due to
the National Science Foundation and to the Office of Naval Research,
for helping to support the author's research
under grants \hbox{MCS 72-03752 A03} and
\hbox{N00014-76-C-0330}. Since the METAFONT
system for typeface design is still under development, the type fonts used
herein are only initial approximations to the eventual ones.\par}
\eject\titlepage
\chapterbegin 21. {Making boxes}
In Chapters 11 and 12 we discussed the idea of boxes and glue; now it is
time to study the various facilities \TEX\ has for making various kinds of
boxes. In most cases, you can get by with boxes that \TEX\ manufactures
automatically with its paragraph builder, page builder, and math formula
processor; but if you want to do nonstandard things, you have the option
of making boxes by yourself.

\danger To make a rule box, type ``{\≡\hrule≡\}'' in vertical mode or
``{\≡\vrule≡\}'' in
horizontal mode, followed if desired by any or all of the specifications
``{\tt width}$\langle$dimen$\rangle$'', ``{\tt height}$\langle$dimen$\rangle$'',
``{\tt depth}$\langle$dimen$\rangle$'', in any order. For example, you can type
``{\≡\vrule height 4pt width 3pt depth 2pt≡\}'' in the middle of a paragraph,
and you will get the black box ``\vrule height 4pt width 3pt depth 2pt''.
If you leave any dimensions unspecified, you get the following by default:
$$\vbox{\halign{\hfill#⊗\qquad\hfill#\hfill\qquad⊗\hfill#\hfill\cr
⊗{\≡\hrule≡\}⊗{\≡\vrule≡\}\cr
width⊗{\tt*}⊗0.4 pt\cr
height⊗0.4 pt⊗{\tt *}\cr
depth⊗0.0 pt⊗{\tt*}\cr}}$$
(Here ``{\tt*}'' means that the rule will extend to the boundary of the smallest
enclosing box.)

\danger To make a box from a horizontal list of boxes, type ``{\≡\hbox{≡\}$\langle
$hlist$\rangle${\≡}≡\}'', where $\langle$hlist$\rangle$ specifies the
list of boxes in restricted horizontal mode. For example, ``{\≡\hbox{This is
not a box}≡\}'' makes the box
\def\boxit#1{\vbox{\hrule\hbox{\vrule\vbox{#1}\vrule}\hrule}}
$$\vcenter{\boxit{\hbox{This is not a box}}}$$
(in spite of what it says). The boundary lines in this illustration aren't typeset,
of course; they merely indicate the box's actual extent, as determined by the rules
of Chapters 11 and 12.

\danger Similarly, the instruction
``{\≡\vbox{≡\}$\langle$vlist$\rangle${\≡}≡\}'' makes a box
from a {\sl vertical} list of boxes. If you type
$$\vbox{\halign{#\hfill\cr
{\≡\vbox{\hbox{T}\hbox{h}\hbox{i}\hbox{s}≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ \hbox{ }\hbox{b}\hbox{o}\hbox{x}}≡\}\cr}}$$
you will get this box:
$$\vcenter{\boxit{\vbox{\hbox{T}\hbox{h}\hbox{i}\hbox{s}\hbox{ }\hbox{b}
\hbox{o}\hbox{x}}}}$$
Automatic baseline adjustment is done on vertical lists, as explained in
Chapter 15. The following example shows what happens if the baseline adjustment
is varied:
$$\vcenter{\halign{#\hfill\cr
{\≡\vbox{\def\\#1{\hbox{#1}}≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ \baselineskip-1pt≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ \lineskip 3pt≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ \\T\\h\\i\\s≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ \\{}\\b\\o\\x}≡\}\cr}}
\hskip 100pt \vcenter{\boxit{
\vbox{\def\\#1{\hbox{#1}}
\baselineskip-1pt
\lineskip 3pt
\\T\\h\\i\\s
\\{}\\b\\o\\x}
}}$$
Note that a specially defined control sequence {\≡\\≡\} saves a lot of typing
in this example.

\danger \exno 21.1: When
the author of this manual first prepared the above example, he
wrote ``{\≡\baselineskip 0pt≡\}'' instead of ``{\≡\baselineskip-1pt≡\}''. Why
didn't this work?

\danger\exno 21.2: How
would you change the above example so that the
letters are {\sl centered} with respect to each other, instead of
being placed flush left?

\danger The phrase ``list of boxes'' in the above discussion really means a
list of boxes and glue. But if {\≡\hbox≡\} and {\≡\vbox≡\} are used in the
simple manner stated, the glue does not stretch or shrink. When you want the
glue to do its thing, type ``{\≡\hbox to ≡\}$\langle$dimen$\rangle${\≡{≡\}$
\langle$hlist$\rangle${\≡}≡\}''
and you will get a box of the specified width; or type
``{\≡\vbox to ≡\}$\langle$dimen$\rangle${\≡{≡\}$\langle$vlist$\rangle${\≡}≡\}''
and you will get a box of the specified height.\xskip (The depth of a {\≡\vbox≡\}ed
box is always the depth of the last box in the vertical list, except that it is
zero when glue follows the last box.)\xskip You may also type
``{\≡\hbox to size{≡\}$\langle$hlist$\rangle${\≡}≡\}'' or
``{\≡\vbox to size{≡\}$\langle$vlist$\rangle${\≡}≡\}''; this means that the
$\langle$dimen$\rangle$ is to be the most recently specified {\≡\hsize≡\} or
{\≡\vsize≡\}, respectively.  Finally, there's a further option of typing
``{\≡\hbox expand ≡\}$\langle$dimen$\rangle${\≡{≡\}$\langle$hlist$\rangle
${\≡}≡\}'' or ``{\≡\vbox expand ≡\}$\langle$dimen$\rangle${\≡{≡\}$\langle$vlist$
\rangle${\≡}≡\}'';
these expand the box to its natural width or height plus the (possibly negative)
amount specified.

\danger You can also get the effect of paragraphing and line-breaking with
{\≡\hbox≡\}, in the following way: If you give the instruction ``{\≡\hbox par≡\}
$\langle$dimen$\rangle$'', \TEX\ will use its
paragraph line-breaking routine to convert the horizontal list into one or
more lines of the specified width. In this case the {\≡\hbox≡\} will actually
result in a box formed from a {\sl vertical} list of horizontal lists of
the desired width. The boxed paragraph that you get is not indented.
$$\hbox par 156pt{For example, the box that you are now
reading was made by typing ``{\≡\hbox
par 156pt{For example, the box≡\}\break
$\ldots$\xskip {\≡five lines.}≡\}'' and \TEX\ broke it
into five lines.}$$

\danger If you specify hanging indentation with such a boxed paragraph, it applies
to the box and not to the paragraph (if any) containing the box. For example,
$$\hbox{{\≡\hbox par 200pt{\hangindent 10 pt ≡\}$\langle$ text $\rangle$ {\≡}≡\}}$$
will put the specified text into a box 200 points wide, where all lines after
the first are indented by 10 points at the left. However, all other parameters
affecting the setting of the boxed paragraph (the baseline skip, raggedness, etc.)
should be set up {\sl before} the {\≡\hbox par≡\}.


\danger You can save a constructed
box for later use by typing ``{\≡\save≡\}$\langle$digit$
\rangle\langle$box$\rangle$, where $\langle$digit$\rangle$ is {\tt0} or {\tt1}
or $\cdots$ or {\tt9} and $\langle$box$\rangle$ specifies a box. For example,
``{\≡\save3\hbox≡penalty0{The formula ≡`≡`$x+y$≡'≡'.}≡\}'' will save away the box
$$\vcenter{\tenpoint\boxit{\hbox{The formula ``$x+y$''.}}}$$
(Note that math formulas are allowed in $\langle$hlist$\rangle$s; but displays
are not.)\xskip
Later you can use this saved box by typing ``{\≡\box≡\}$\langle$digit$
\rangle$''. The {\≡\save≡\} and {\≡\box≡\} instructions are useful for constructing
rather complex layouts like those in a newspaper page. Caution: You can use a
saved box only once; after you type ``{\≡\box3≡\}'' the contents of box 3 becomes
null. If you type ``{\≡\save3\box2≡\}'' the effect is to move box 2 to box 3
and then to make box 2 empty.

\save4\hbox par 300pt{\exno 21.3: Define a control
sequence {\≡\boxit≡\} so that ``{\≡\boxit{≡\}$\langle$box$\rangle${\≡}≡\}''
yields the given box surrounded by 3 points of space and ruled lines on all
four sides. For example, this exercise has been typeset by telling \TEX\ to
{\≡\boxit{\boxit{\box4}}≡\}, where box 4 was created by typing ``{\≡\save4\hbox
par 300pt{\exno 21.3: Define ...}≡\}''.}
\def\boxit#1{\vbox{\hrule
\hbox{\vrule\hskip 3pt\vbox{\vskip 3pt #1 \vskip 3pt}\hskip 3pt\vrule}
\hrule}}
\danger \lower 55pt\boxit{\boxit{\box4}}

\danger To raise or lower a constructed
box in a horizontal list, or in a math formula,
precede it by ``{\≡\raise≡\}$\langle$dimen$\rangle$'' or
``{\≡\lower≡\}$\langle$dimen$\rangle$''. For example, the {\≡\TEX≡\} control
sequence that prints the \TEX\ logo in this manual is defined by
$$\hbox{\≡\def\TEX{\hbox{\:aT\hskip-.1667em\lower.424ex\hbox{E}\hskip-.125em X}}≡\}$$
Similarly, you can move a constructed
box left or right in a vertical list if you type
``{\≡\moveleft≡\}$\langle$dimen$\rangle$''
or ``{\≡\moveright≡\}$\langle$dimen$\rangle$'' just before its description.
The control sequences {\≡\vcenter≡\} and {\≡\vtop≡\} are also useful for box
positioning (see Chapter 26).

\danger There is also a way to repeat a box as many times as necessary to fill up
some given space; this is what printers call ``leaders.''
The general construction is ``{\≡\leaders≡\}$\langle$box or rule$\rangle\langle
$glue$\rangle$'', where $\langle$box or rule$\rangle$ is any box or rule
specified by {\≡\hbox≡\} or {\≡\vbox≡\} or {\≡\box≡\} or {\≡\page≡\} or
{\≡\hrule≡\} or {\≡\vrule≡\}, and where $\langle$glue$\rangle$ is specified
by {\≡\hskip≡\} or {\≡\hfill≡\} in horizontal mode, {\≡\vskip≡\} or {\≡\vfill≡\}
in vertical mode. \TEX\ treats the glue in the normal way, possibly stretching
it or shrinking it; but then instead of leaving the resulting space blank,
\TEX\ places the contents of the box there, as many times as it will fit,
subject to the condition that the reference point of each box will be congruent
to some fixed number, modulo the box's width (in horizontal leaders) or modulo
the box's height plus depth (in vertical leaders). This ``congruence'' means that
leaders in different places will line up with each other. For example,
$$\vbox{\halign{#\hfill\cr
{\≡\def\lead{\leaders\hbox to 10pt{\hfill.\hfill}\hfill}≡\}\cr
{\≡\hbox to size{Alpha\lead Omega}≡\}\cr
{\≡\hbox to size{The Beginning\lead The Ending}≡\}\cr}}$$
will produce the following two lines:
$$\vcenter{
\def\lead{\leaders\hbox to 10pt{\hfill.\hfill}\hfill}
\hbox to size{Alpha\lead Omega}
\hbox to size{The Beginning\lead The Ending}
}$$
(Here ``{\≡\hbox to 10pt{\hfill.\hfill}≡\}'' specifies a box 10 points wide,
with a period in its center; the control sequence {\≡\lead≡\} then
causes this box to be replicated when filling another box.)\xskip
When a rule is used
as a leader, it completely fills the glue space; for example, if we had made
the definition ``{\≡\def\lead{\leaders\hrule\hfill}≡\}'', the two lines
would have come out looking this way instead:
$$\vcenter{
\def\lead{\leaders\hrule\hfill}
\hbox to size{Alpha\lead Omega}
\hbox to size{The Beginning\lead The Ending}
}$$

\vskip-6pt
\danger Leaders can be used in an interesting way to construct variable-width
braces in the horizontal direction. \TEX's math extension font cmathx (used with
{\tt basic} format) contains four characters that allow you to typeset such
braces in the following way. First make the definitions
$$\vbox{\halign{#\hfill\cr
{\≡\def\bracex{\leaders\hrule height 1.5pt \hfill}≡\}\cr
{\≡\def\dnbrace{$\char≡'772$\bracex$\char≡'775≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ \char≡'774$\bracex$\char≡'773$}≡\}\cr
{\≡\def\upbrace{$\char≡'774$\bracex$\char≡'773≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ \char≡'772$\bracex$\char≡'775$}≡\}\cr}}$$
Then
$$\vbox{\halign{#\hfill\cr
{\≡\hbox to 100pt{\dnbrace}≡\}\cr
{\≡\hbox to 200pt{\upbrace}≡\}\cr}}$$
will produce
$$\def\bracex{\leaders\hrule height 1.5pt \hfill}
\def\dnbrace{$\char'772$\bracex$\char'775
              \char'774$\bracex$\char'773$}
\def\upbrace{$\char'774$\bracex$\char'773
              \char'772$\bracex$\char'775$}
\vcenter{\hbox to 100pt{\dnbrace}
\hbox to 200pt{\upbrace}}$$
This is occasionally useful in connection with math formulas.

\danger \exno 21.4: How do you think the author of this manual made asterisks
fill the rest of the current page? [{\sl Hint:} The asterisk used (in font
cmr10) has a height of 7.5 points.] \enddanger

\leaders\chop to 0pt{\hbox to size{\hfill*\lower 3.75pt\hbox{*}\!
*\lower 3.75pt\hbox{*}*}}\vfill
\specialchapterbegin 22. {Alignment}
A novice \TEX\ user can prepare manuscripts that involve mathematical
formulas but no complicated tables; but a \TEX\ Master can prepare complicated
tables using {\≡\halign≡\} or {\≡\valign≡\}. In this chapter, if you're
ready for it, you can learn to be a \TEX\ Master.\xskip
(And the next chapter---which
talks about the design of {\≡\output≡\} routines---will enable you to
become a Grandmaster.)

\danger For simplicity, let's consider {\≡\halign≡\} first; {\≡\valign≡\} is
similar, and it is used much more rarely. If you type
$$\hbox{{\≡\halign to ≡\}$\langle$dimen$\rangle${\≡{≡\}$\langle$alignment
preamble$\rangle${\≡\cr≡\}$\langle$alignment entries$\rangle${\≡}≡\}}$$
in vertical mode or restricted vertical mode, you append a list of aligned
boxes that are each $\langle$dimen$\rangle$ units wide to the current
vertical list; these boxes are formed from the $\langle$alignment entries$\rangle$
by using the specifications in the $\langle$alignment preamble$\rangle$. We've
already seen examples of alignment in Chapter 18, where {\≡\halign≡\} was
used to construct matrices. In general, the preamble tells how to format individual
vertical columns whose entries are going to be assembled into horizontal rows of the
specified width. Before we get into any details of the alignment, let's
observe straightaway that ``{\≡\halign to ≡\}$\langle$dimen$\rangle$''
can be changed to ``{\≡\halign to size≡\}'' if the $\langle$dimen$\rangle$
 is to be the current
{\≡\hsize≡\}; it can be shortened to simply ``{\≡\halign≡\}'' if the minimum
size (without shrinking) is desired, or replaced by ``{\≡\halign expand
≡\}$\langle$dimen$\rangle$'' if the boxes should be stretched to a given amount
in addition to this minimum size. In other words, {\≡\halign≡\} has the same
four options as {\≡\hbox≡\}.

\danger The $\langle$alignment preamble$\rangle$ consists of one or more
$\langle$format$\rangle$ specifications separated by {\≡⊗≡\}'s. Each $\langle
$format$\rangle$ specification is a sequence of tokens that is properly nested
with respect to {\≡{...}≡\} groups and contains exactly one ``{\≡#≡\}''.
For example, the $\langle$alignment preamble$\rangle$ suggested for three-column
matrices in Chapter 18 was
$$\hbox{\≡$\ctr{#}$\quad⊗$\ctr{#}$\quad⊗$\ctr{#}$≡\}\quad.$$
A $\langle$format$\rangle$ is essentially a simple {\≡\def≡\} with one parameter;
the idea is to replace the {\≡#≡\} by whatever alignment entry is typed in
that column position. For example, if the $\langle$alignment entries$\rangle$
following this preamble are
$$\hbox{\≡x≡↓1⊗x≡↓2⊗x≡↓3\cr y≡↓1⊗y≡↓2⊗y≡↓3\cr≡\}$$
then there will be two rows of the matrix obtained by substituting these entries
in the preamble, namely
$$\vcenter{\halign{#\cr
{\≡$\ctr{x≡↓1}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{x≡↓2}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{x≡↓3}$≡\}\cr
{\≡$\ctr{y≡↓1}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{y≡↓2}$\quad≡ ≡ ≡ ≡ ≡ $\ctr{y≡↓3}$≡\}\cr}}$$
The $\langle$alignment entries$\rangle$ consist of zero or more $\langle$row$
\rangle$s; and a $\langle$row$\rangle$ is one or more entries separated by
{\≡⊗≡\}'s and followed by {\≡\cr≡\}. In general if the preamble contains $n$
$\langle$format$\rangle$s
$$\tabskip 0pt plus 10000000000pt
\halign to size{\ctr{$# $}\tabskip 0pt⊗#⊗\ctr{$# $}⊗#⊗\ctr{$#
$}⊗#⊗\ctr{$# $}⊗#\hfill\tabskip 0pt plus 10000000000pt\cr
\langle u↓1\rangle\hbox{\tt\char'43}\langle v↓1\rangle⊗{\≡⊗≡\}⊗
\langle u↓2\rangle\hbox{\tt\char'43}\langle v↓2\rangle⊗{\≡⊗≡\}⊗\;\;\cdots\;\;
⊗{\≡⊗≡\}⊗\langle u↓n\rangle\hbox{\tt\char'43}\langle v↓n\rangle\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{and if there are $m$ rows each containing $n$ entries}
\vskip 11pt plus 3pt minus 8pt}
\langle x↓{11}\rangle⊗{\≡⊗≡\}⊗\langle x↓{12}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{1n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\langle x↓{21}\rangle⊗{\≡⊗≡\}⊗\langle x↓{22}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{2n}\rangle⊗{\≡\cr≡\}\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle x↓{m1}\rangle⊗{\≡⊗≡\}⊗\langle x↓{m2}\rangle⊗{\≡⊗≡\}⊗
\cdots⊗{\≡⊗≡\}⊗\langle x↓{mn}\rangle⊗{\≡\cr≡\}\cr
\noalign{\vskip 11pt plus 3pt minus 8pt
\hbox{we will obtain $mn$ fleshed-out entries}
\vskip 11pt plus 3pt minus 8pt}
\langle u↓1\rangle\langle x↓{11}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{12}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{1n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{21}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{22}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{2n}\rangle\langle v↓n\rangle\cr
\noalign{\penalty 1000}
\vdots⊗⊗\vdots⊗⊗⊗⊗\vdots\cr
\noalign{\penalty 1000}
\langle u↓1\rangle\langle x↓{m1}\rangle\langle v↓1\rangle⊗⊗
\langle u↓2\rangle\langle x↓{m2}\rangle\langle v↓2\rangle⊗⊗\cdots⊗⊗
\langle u↓n\rangle\langle x↓{mn}\rangle\langle v↓n\rangle\cr}$$
by repeatedly copying the preamble format information.

\danger Now here's what \TEX\ does with the $mn$ fleshed-out entries: The
natural width of each entry {\≡\hbox{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\} is determined; and the {\sl maximum}
natural width is computed in each column. Suppose that $w↓j$ is the maximum natural
width in the $j$th column; then each fleshed-out entry in that column
is replaced by the
box ``{\≡\hbox to ≡\}$w↓j${\≡{≡\}$\langle u↓j\rangle\langle x↓{ij}
\rangle\langle v↓j\rangle${\≡}≡\}''. Thus, all entries in a particular column
now have the same width. Finally these boxes are welded together to make the
$m$ rows, by inserting $n+1$ elements of glue in each row (before the first
box, between boxes, and after the last box). The glue to use in this welding
process has previously been specified by ``{\≡\tabskip≡\}$\langle$glue$\rangle$''.
The $m$ row boxes are finally appended to the current vertical list.

\danger If you don't understand what was said so far, look back at the matrix
example and reread the above until you understand. Because there are also some
refinements that we shall now discuss.\xskip (a) After any {\≡\cr≡\} you can
type ``{\≡\noalign{≡\}$\langle$vlist$\rangle${\≡}≡\}'', and this $\langle$vlist$
\rangle$ will simply appear in its place among the aligned row boxes. The
$\langle$vlist$\rangle$
in this case usually contains vertical glue, penalty specifications,
or horizontal rules; but it might contain anything that is allowed in restricted
vertical mode, even another {\≡\halign≡\}.\xskip(b) If some row has fewer than
$n$ entries, i.e., if the {\≡\cr≡\} of some row occurs before there have been
$n-1$ {\≡⊗≡\}'s, all remaining columns of the row are set to null boxes
regardless of their format.\xskip
(This is not necessarily the same as ``{\≡\hbox{≡\}$
\langle u↓j\rangle\langle v↓j\rangle${\≡}≡\}''; the preamble formats are
simply ignored.)\xskip (c) If you specify {\≡\tabskip≡\}$\langle$glue$\rangle$
in the preamble, the $n+1$ globs of glue that weld together the final row
boxes will be different, so you can get different spacing between columns.
Here's how it works: The glue placed before column 1 is the {\≡\tabskip≡\} glue
in effect when the {\≡\halign≡\} control sequence itself appears; the glue
that replaces a {\≡⊗≡\} or {\≡\cr≡\} is the {\≡\tabskip≡\} glue in effect
when that {\≡⊗≡\} or {\≡\cr≡\} appears in the preamble.

\danger Warning: Any spaces you type in the $\langle$format$\rangle$s of the
preamble will be taken seriously! Don't start a new line after a {\≡⊗≡\} unless
you intend a corresponding space to be there in every column.\xskip (You may, of
course, start a new line after {\≡\cr≡\} without inserting an unwanted space,
or you can type ``{\≡⊗\!≡\}'' and go to a new line.)\xskip The same applies to
spaces in the aligned entries; {\sl always be extra careful with your use of
spaces inside {\≡\halign≡\}.}

\danger Another warning: Don't use a construction like ``{\≡$#$≡\}'' in your
$\langle$format$\rangle$s if the corresponding column entries might be
null. Otherwise \TEX\ will scan ``{\≡$$≡\}'' and think display math is
intended, and this probably will lead to hopeless confusion.\xskip
(The matrix example
above has ``{\≡$\ctr{#}$≡\}'' instead of ``{\≡\ctr{$#$}≡\}'' for precisely this
reason. Another safe possibility would be ``{\≡\ctr{$# $}≡\}''.)

\ddanger You can have {\≡\halign≡\} or {\≡\valign≡\} within {\≡\halign≡\}
or {\≡\valign≡\} (for example, matrices within aligned equations). In order
to allow this, \TEX\ insists that {\≡{≡\} and {\≡}≡\} be balanced in alignment
entries, so that it is possible to distinguish which level of alignment
corresponds to a given {\≡⊗≡\} or {\≡\cr≡\}. Consider, for example, the
extremely simple alignment
$$\vbox{\halign{#\hfill\cr
{\≡\halign{\ctr{#}\cr≡\}\cr
{\≡≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡ ≡\}$\langle$entry$\rangle${\≡\cr}≡\}\quad.\cr}}$$
When \TEX\ begins to scan the alignment entry, it scans the string of
tokens ``{\≡\ctr{≡\}\penalty0
$\langle$entry$\rangle${\≡\cr}...≡\}''; and the appearance
of ``{\≡\ctr≡\}'' causes \TEX\ to look for {\≡\ctr≡\}'s argument. This
argument begins with ``{\≡{≡\}'', so the scanning continues until the matching
``{\≡}≡\}''. However, when the {\≡\cr≡\} is encountered after
$\langle$entry$\rangle$, \TEX\ is supposed to insert the matching ``{\≡}≡\}''
from the preamble. If $\langle$entry$\rangle$ itself contains a use of
{\≡\halign≡\}, there will be {\≡\cr≡\}'s in the middle of $\langle$entry$\rangle$;
so \TEX\ doesn't simply look for the first {\≡\cr≡\}. Instead it ignores the
tokens {\≡⊗≡\} and {\≡\cr≡\} until finding one that is not enclosed in
braces, thereby correctly determining the argument to {\≡\ctr≡\}.

\ddanger Defined control sequences in the preamble are not usually expanded
until the alignment entries are being processed.
However, a control sequence following ``{\≡\tabskip≡\}$\langle$glue$\rangle$''
in the preamble might be expanded, since a $\langle$glue$\rangle$ specification
might involve control sequences. For example, ``{\≡\tabskip 0pt \ctr{#}≡\}''
will effectively be expanded by \TEX\ to ``{\≡\tabskip 0pt \hfill # \hfill≡\}''
while the preamble is being scanned, because \TEX\ won't know (when it gets
to ``{\≡\ctr≡\}'') whether or not the expansion of this control sequence will
begin with ``{\≡plus 1pt≡\}'' or some other continuation of the glue
specification.

\danger In the rest of this chapter we shall discuss two worked-out examples.
First suppose that we want to typeset three
pairs of displayed formulas whose = signs are to be aligned, such as
$$\vcenter{\halign{\rt{$#$}⊗\lft{$\null=#$}\qquad
⊗\rt{$#$}⊗\lft{$\null=#$}\qquad
⊗\rt{$#$}⊗\lft{$\null=#$}\cr
V↓i⊗v↓i-q↓iv↓j,⊗X↓i⊗x↓i-q↓ix↓j,⊗U↓i⊗u↓i,\qquad\hbox{for }i≠j;\cr
V↓j⊗v↓j,⊗X↓j⊗x↓j,⊗U↓j⊗u↓j+\sum↓{i≠j}q↓iu↓i.\cr}}\eqno(13)$$
We could do this with three {\≡\eqalign≡\}'s, but let's not, since our
current goal is to learn more about the general {\≡\halign≡\} construction.
One solution is to type
$$\vbox{\halign{#\hfill\cr
{\≡$$\vcenter{\halign{≡\}$\langle$alignment preamble$\rangle${\≡\cr≡\}\cr
{\≡V≡↓i⊗v≡↓i-q≡↓iv≡↓j,⊗X≡↓i⊗x≡↓i-q≡↓ix≡↓j,⊗U≡↓i⊗u≡↓i,\qquad\hbox{for }i≡spose
/=j;\cr≡\}\cr
{\≡V≡↓j⊗v≡↓j,⊗X≡↓j⊗x≡↓j,⊗U≡↓j⊗u≡↓j+\sum≡↓{i≡spose/=j}q≡↓iu≡↓i.\cr}}\eqno(13)$$≡\}\cr
}}$$
with some suitable alignment preamble.\xskip
(It sometimes helps to figure out how you
want to type the alignment entries before you design the preamble; there's a
tradeoff between ease of typing the entries and ease of constructing the
preamble.)\xskip One suitable preamble is
$$\vbox{\halign{#\hfill\cr
{\≡$\rt{#}$⊗\lft{$\null=#$}\qquad≡\}\cr
{\≡⊗$\rt{#}$⊗\lft{$\null=#$}\qquad≡\}\cr
{\≡⊗$\rt{#}$⊗\lft{$\null=#$}≡\}\cr}}\quad.$$
Note the {\≡\null≡\}s here: they ensure proper spacing before the = signs,
because the equations are being broken into two parts. Study this example
carefully and you'll soon see how to make useful alignments.

\danger \exno 22.1: What would happen if ``{\≡\vcenter≡\}'' were replaced by
``{\≡\vbox≡\}'' in the above example?

\danger If we didn't
have to include an equation number like ``(13)'', the {\≡\vcenter≡\} could
have been omitted; but then there would have been a possible page break between
the two equations, and the equations would not have been centered on the line.\xskip
(The only effect of the {\≡$$≡\}'s in ``{\≡$$\halign{...}$$≡\}'' is to insert
{\≡\dispskip≡\} glue above and below the alignment.)\xskip One way to prevent a
page break would be to insert ``{\≡\noalign{\penalty 1000}≡\}'' between
the lines. And one way to center the equations would be to vary the
tabskip glue, as in the definition of {\≡\eqalignno≡\} in Appendix B. But it
is much easier to use {\≡\vcenter≡\}.

\danger The second example is slightly more complex, but once you master it
you will have little or no trouble with other tables. Suppose you want to
specify this:
$$\vbox{\tabskip 0pt
\def\|{\vrule height 9.25pt depth 3pt}
\def\.{\hskip-10pt plus 10000000000pt}
\hrule
\hbox to 150pt{\|\.AT&T Common Stock\.\|}
\hrule
\halign to 150pt{#\tabskip 0pt plus 100pt
⊗\hfill#⊗#⊗\ctr{#}⊗#⊗\hfill#⊗#\tabskip 0pt\cr
\|⊗\.Year\.\hfill⊗\|⊗\.Price\.⊗\|⊗\.Dividend\.\hfill⊗\|\cr
\noalign{\hrule}
\|⊗1971⊗\|⊗41--54⊗\|⊗$\$$2.60⊗\|\cr
\noalign{\hrule}
\|⊗2⊗\|⊗41--54⊗\|⊗2.70⊗\|\cr
\noalign{\hrule}
\|⊗3⊗\|⊗46--55⊗\|⊗2.87⊗\|\cr
\noalign{\hrule}
\|⊗4⊗\|⊗40--53⊗\|⊗3.24⊗\|\cr
\noalign{\hrule}
\|⊗5⊗\|⊗45--52⊗\|⊗3.40⊗\|\cr
\noalign{\hrule}
\|⊗6⊗\|⊗51--59⊗\|⊗.95\spose*⊗\|\cr
\noalign{\hrule}}
\vskip 3pt
\hbox{*(first quarter only)}}$$
including all those horizontal and vertical lines. The table is to be 150
points wide. Here is one way to do it, letting the tabskip glue expand to
give the column widths (so that, for example, the ``Price'' column will turn out
to be exactly one en-dash-width wider than the ``Year'' column):
$$\halign{\hskip 10pt#\cr
{\≡$$\vbox{\tabskip 0pt≡\}\cr
{\≡\def\|{\vrule height 9.25pt depth 3pt}≡\}\cr
{\≡\def\.{\hskip-10pt plus 10000000000pt}≡\}\cr
{\≡\hrule≡\}\cr
{\≡\hbox to 150pt{\|\.AT&T Common Stock\.\|}≡\}\cr
{\≡\hrule≡\}\cr
{\≡\halign to 150pt{#\tabskip 0pt plus 100pt≡\}\cr
{\≡⊗\hfill#⊗#⊗\ctr{#}⊗#⊗\hfill#⊗#\tabskip 0pt\cr≡\}\cr
{\≡\|⊗\.Year\.\hfill⊗\|⊗\.Price\.⊗\|⊗\.Dividend\.\hfill⊗\|\cr≡\}\cr
{\≡\noalign{\hrule}≡\}\cr
{\≡\|⊗1971⊗\|⊗41--54⊗\|⊗$\$$2.60⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗2⊗\|⊗41--54⊗\|⊗2.70⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗3⊗\|⊗46--55⊗\|⊗2.87⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗4⊗\|⊗40--53⊗\|⊗3.24⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗5⊗\|⊗45--52⊗\|⊗3.40⊗\|\cr\noalign{\hrule}≡\}\cr
{\≡\|⊗6⊗\|⊗51--59⊗\|⊗.95\spose*⊗\|\cr\noalign{\hrule}}≡\}\cr
{\≡\vskip 3pt≡\}\cr
{\≡\hbox{*(first quarter only)}}$$≡\}\cr}$$

\vskip-6pt
\danger Here is an explanation of this rather long sequence of commands:
The control sequence ``{\≡\|≡\}'' is defined to be a vertical rule that
guarantees appropriate spacing of baselines between individual rows.\xskip
(\TEX\ doesn't use {\≡\baselineskip≡\} and {\≡\lineskip≡\} before or after
horizontal rules.)\xskip
The alignment is defined in such a way that the {\≡\tabskip≡\}
glue is zero at the left and right of the alignment, but it is ``{\tt 0pt plus
100pt}'' between columns; this glue will therefore
expand to make the columns equally
spaced. There are seven (not three) columns, since the vertical rules are
considered to be
columns. The preamble has just ``{\≡#≡\}'' for the columns that are to be
vertical rules; the ``Year'' column and ``Dividend'' column both have format
``{\≡\hfill#≡\}'', causing them to be right-justified, while the ``Price''
column has format ``{\≡\ctr{#}≡\}''. The top row of the table appears
before the {\≡\halign≡\}, since it does not have to be aligned with
the other rows. In the second row of the table, an extra ``{\≡\hfill≡\}''
has been typed after ``Year'' and ``Dividend'', to compensate for the
fact that the columns are being right-justified yet the titles are supposed to
be centered. The special control sequence ``{\≡\.≡\}'' is also placed around
these title words; this is somewhat tricky. It has the effect of telling
\TEX\ to ignore the width of the title words when computing the column widths.
The asterisk in the final row of the table is preceded by ``{\≡\spose≡\}'' in
order to make it zero-width, otherwise the decimal points wouldn't line up
properly.

\danger Another way to get vertical and horizontal rules into tables is to
typeset without them, then back up (using negative glue) and insert them.

\danger The control sequence {\≡\valign≡\} is analogous to {\≡\halign≡\}, but
with rows and columns changing r\A oles. In this case {\≡\cr≡\} marks the
bottom of a column. The boxes in each row will line up as if their reference
points were at the bottom; in other words, their depth is effectively set
to zero by modifying their height.\enddanger

\par\vfill\end